package com.zbkj.crmeb.task.product;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import com.xxl.job.core.handler.annotation.XxlJob;
import com.zbkj.crmeb.pdd.service.PddAccountService;
import com.zbkj.crmeb.store.service.StoreProductService;

/**
 * @author stivepeim
 * @title: ProductStock
 * @projectName crmeb
 * @description: 操作商品库存
 * @date 2020/8/2017:04
 */

@Component
@Configuration //读取配置
public class ProductStock {
    //日志
    private static final Logger logger = LoggerFactory.getLogger(ProductStock.class);

    @Value("${switch.task.ProductStockTask:true}")
    Boolean runable = true;

    @Autowired
    private StoreProductService storeProductService;
    @Autowired
    private PddAccountService pddAccountService;

    //1分钟同步一次数据
    @XxlJob("productStock")
    public void init(){
        // 测试环境关闭了
        if(!runable){
            return;
        }
        try {
            storeProductService.consumeProductStock();
        }catch (Exception e){
            logger.error("OrderTakeByUser.task error ! e: " ,e);
        }
    }
    
    // 更新拼多多已推送商品库存
    @XxlJob("pddProductStockUpdate")
    public void pddProductStockUpdate(){
    	try {
    		pddAccountService.goodsStockJobUpdate();
    	} catch (Exception e){
    		logger.error("pddProductStockUpdate.task error ! e: " ,e);
    	}
    }
}
